package cn.stylefeng.guns.modular.business.app.controller;

import cn.stylefeng.guns.core.enums.CoreExceptionEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.modular.business.app.RyController;
import cn.stylefeng.guns.modular.business.app.controller.req.LoginReqVo;
import cn.stylefeng.guns.modular.business.util.BusinessUtil;
import cn.stylefeng.guns.modular.business.util.JudgeLogicUtil;
import cn.stylefeng.guns.sys.modular.user.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author liuyao
 */
@Deprecated
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/api")
public class ApiLoginController extends RyController {

    @Autowired
    private SysUserService customerService;

    @Resource
    private JudgeLogicUtil judgeLogicUtil;

    @Resource
    private BusinessUtil businessUtil;

    /**
     * 登录
     *
     * @return
     */
    @PostMapping("/login")
    public ResponseData login(@Valid @RequestBody LoginReqVo loginReqVo) {
        return pwdLogin(loginReqVo);
    }


    /**
     * 密码
     *
     * @param loginReqVo
     * @return
     */
    private ResponseData pwdLogin(LoginReqVo loginReqVo) {
        //验证登入账号
        Long userId = judgeLogicUtil.checkLoginUser(loginReqVo);

        //验证密码
        if (!businessUtil.loginPwdTrue(userId, 1, loginReqVo.getPassword())) {
            return ResponseData.error(CoreExceptionEnum.PWD_ERROR);
        }
        return businessUtil.getToken(userId, 1);
    }


    //
    ///**
    // * 绑定手机号
    // *
    // * @return
    // */
    //@PostMapping("/bindAccount")
    //public ResponseData bindAccount(@Valid @RequestBody LoginReqVo loginReqVo) {
    //    return customerService.bindAccount(loginReqVo);
    //}
    //
    ///**
    // * 个人信息
    // *
    // * @return
    // */
    //@UserLoginToken
    //@PostMapping("/info")
    //public ResponseData info() {
    //    return customerService.info(getUserVo());
    //}
    //
    //
    ///**
    // * 修改用户信息
    // *
    // * @return
    // */
    //@UserLoginToken
    //@RequestMapping(value = "/editInfo", method = RequestMethod.POST)
    //@ApiOperation(value = "修改用户信息")
    //public ResponseData editInfo(@RequestBody CustomerEditReqVo customerEditReqVo) {
    //    return customerService.editInfo(customerEditReqVo, getUserVo());
    //}
    //
    ///*  */
    //
    ///**
    // * 注册
    // *
    // * @param req
    // * @return
    // *//*
    //@PostMapping("/register")
    //public ResponseData register(@Valid @RequestBody RegisterReq req) {
    //    return customerService.register(req);
    //}*/
    //@UserLoginToken
    //@RequestMapping(value = "/forgetPayPwd", method = RequestMethod.POST)
    //@ApiOperation(value = "忘记支付密码")
    //public ResponseData forgetPayPwd(@RequestBody @Valid UserForgetPwdLoginReq req) {
    //    return customerService.forgetPayPwd(req, getUserVo());
    //}
    //
    //@UserLoginToken
    //@RequestMapping(value = "/checkPayPwd", method = RequestMethod.POST)
    //@ApiOperation(value = "校验支付密码")
    //public ResponseData checkPayPwd(@RequestBody String pwd) {
    //    return customerService.checkPayPwd(pwd, getUserVo());
    //}
    //
    //@UserLoginToken
    //@RequestMapping(value = "/editPayPwd", method = RequestMethod.POST)
    //@ApiOperation(value = "修改支付密码")
    //public ResponseData editPayPwd(@RequestBody String pwd) {
    //    return customerService.editPayPwd(pwd, getUserVo());
    //}
    //
    //
    //@UserLoginToken
    //@RequestMapping(value = "/editPwd", method = RequestMethod.POST)
    //@ApiOperation(value = "修改密码")
    //public ResponseData editPwd(@RequestBody UserEditPwdLoginReq req) {
    //    return customerService.editPwd(req, getUserVo());
    //}
    //
    //
    //@RequestMapping(value = "/forgetPwd", method = RequestMethod.POST)
    //@ApiOperation(value = "忘记密码")
    //public ResponseData forgetPwd(@RequestBody @Valid UserForgetPwdLoginReq req) {
    //    return customerService.forgetPwd(req);
    //}
    //
    //
    //@RequestMapping(value = "/checkOldMobile", method = RequestMethod.POST)
    //@ApiOperation(value = "校验旧手机号")
    //public ResponseData checkOldMobile(@RequestBody @Valid CheckOldMobileReq req) {
    //    return customerService.checkOldMobile(req, getUserVo());
    //}
    //
    //
    //@RequestMapping(value = "/changeBindingMobile", method = RequestMethod.POST)
    //@ApiOperation(value = "换绑手机号")
    //public ResponseData changeBindingMobile(@RequestBody @Valid ChangeBindingMobileReq req) {
    //    return customerService.changeBindingMobile(req, getUserVo());
    //}
    //
    ///**
    // * 注销
    // *
    // * @return
    // */
    //@PostMapping("/cancellation")
    //@UserLoginToken
    //public ResponseData cancellation() {
    //    return this.customerService.cancellation(getUserVo());
    //}
    //
    //
    ///**
    // * 退出
    // *
    // * @return
    // */
    //@UserLoginToken
    //@PostMapping("/logout")
    //public ResponseData logout() {
    //    return this.customerService.logout(getUserVo());
    //}
    //
    //
    ///**
    // * 微信获取openId
    // *
    // * @param code
    // * @return
    // */
    //@PostMapping("/getOpenid")
    //public ResponseData getOpenid(@RequestBody @Valid @NotBlank(message = "code不能为空") String code) {
    //    return customerService.getOpenId(code);
    //}
    //
    //
    ///**
    // * 根据手机号获取用户信息
    // *
    // * @return
    // */
    //@UserLoginToken
    //@PostMapping("/getInfoByMobile")
    //public ResponseData getInfoByMobile(@RequestBody String mobile) {
    //    return customerService.getInfoByMobile(mobile);
    //}


}
